package com.grass.p019lv.novel.viewmodel;

import androidx.core.app.NotificationCompat;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.androidx.p013lv.base.bean.novel.NovelChapterBean;
import com.androidx.p013lv.base.bean.novel.NovelDetailBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.JsonParams;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.utils.JsonUtils;
import com.grass.appointment.bean.CommentBean;
import com.grass.appointment.bean.ReplyBean;
import com.lzy.okgo.model.Response;
import com.yalantis.ucrop.view.CropImageView;

/* renamed from: com.grass.lv.novel.viewmodel.NovelModel */
public class NovelModel extends ViewModel {
    private MutableLiveData<BaseRes<String>> collectNovel;
    private MutableLiveData<BaseRes<CommentBean>> commentBean;
    private MutableLiveData<BaseRes<NovelChapterBean>> novelChapterInfo;
    private MutableLiveData<BaseRes<NovelDetailBean>> novelInfo;
    private MutableLiveData<BaseRes<ReplyBean>> replyBean;

    public MutableLiveData<BaseRes<NovelChapterBean>> getNovelChapterInfoData() {
        if (this.novelChapterInfo == null) {
            this.novelChapterInfo = new MutableLiveData<>();
        }
        return this.novelChapterInfo;
    }

    public MutableLiveData<BaseRes<CommentBean>> addComment() {
        if (this.commentBean == null) {
            this.commentBean = new MutableLiveData<>();
        }
        return this.commentBean;
    }

    public MutableLiveData<BaseRes<ReplyBean>> addCommentReply() {
        if (this.replyBean == null) {
            this.replyBean = new MutableLiveData<>();
        }
        return this.replyBean;
    }

    public MutableLiveData<BaseRes<NovelDetailBean>> getNovelInfoData() {
        if (this.novelInfo == null) {
            this.novelInfo = new MutableLiveData<>();
        }
        return this.novelInfo;
    }

    public void commitComment(int i, String str) {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().commitComment(), JsonParams.build().add(Key.VIDEO_ID, Integer.valueOf(i)).add("content", str).commit(), new HttpCallback<BaseRes<CommentBean>>("saveComment") {
            /* class com.grass.p019lv.novel.viewmodel.NovelModel.C32151 */

            public void onLvSuccess(BaseRes<CommentBean> baseRes) {
            }

            @Override // com.androidx.p013lv.base.http.callback.HttpCallback, com.lzy.okgo.callback.Callback
            public void onSuccess(Response<BaseRes<CommentBean>> response) {
                NovelModel.this.commentBean.setValue(response.body());
            }

            @Override // com.androidx.p013lv.base.http.callback.HttpCallback, com.lzy.okgo.callback.AbsCallback, com.lzy.okgo.callback.Callback
            public void onError(Response<BaseRes<CommentBean>> response) {
                super.onError(response);
                try {
                    String message = response.getException().getMessage();
                    NovelModel.this.commentBean.setValue(new BaseRes(JsonUtils.getInt("code", message), JsonUtils.getString(NotificationCompat.CATEGORY_MESSAGE, message)));
                } catch (Exception unused) {
                    NovelModel.this.commentBean.setValue(new BaseRes(CropImageView.DEFAULT_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION, ""));
                }
            }
        });
    }

    public void getNovelInfo(int i) {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getNovelInfo(i), new HttpCallback<BaseRes<NovelDetailBean>>("novelInfo") {
            /* class com.grass.p019lv.novel.viewmodel.NovelModel.C32162 */

            public void onLvSuccess(BaseRes<NovelDetailBean> baseRes) {
                NovelModel.this.novelInfo.setValue(baseRes);
            }
        });
    }

    public void getNovelChpaterInfo(int i, int i2) {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getNovelChapterInfo(i, i2), new HttpCallback<BaseRes<NovelChapterBean>>("novelChapterInfo") {
            /* class com.grass.p019lv.novel.viewmodel.NovelModel.C32173 */

            public void onLvSuccess(BaseRes<NovelChapterBean> baseRes) {
                NovelModel.this.novelChapterInfo.setValue(baseRes);
            }
        });
    }

    public void collectNovel(int i, boolean z) {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().collectNovel(), JsonParams.build().add("fictionId", Integer.valueOf(i)).add("isLike", Boolean.valueOf(z)).commit(), new HttpCallback<BaseRes<String>>("collectNovel") {
            /* class com.grass.p019lv.novel.viewmodel.NovelModel.C32184 */

            public void onLvSuccess(BaseRes<String> baseRes) {
            }
        });
    }

    public void attentionAnChorNovel(int i, boolean z) {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().attentionAnChorNovel(), JsonParams.build().add("anchorId", Integer.valueOf(i)).add("isAttention", Boolean.valueOf(z)).commit(), new HttpCallback<BaseRes<String>>("attentionAnChorNovel") {
            /* class com.grass.p019lv.novel.viewmodel.NovelModel.C32195 */

            public void onLvSuccess(BaseRes<String> baseRes) {
            }
        });
    }

    public void cancelHttp() {
        HttpUtils.getInsatance().cancelTag("userInfo");
        HttpUtils.getInsatance().cancelTag("novelInfo");
        HttpUtils.getInsatance().cancelTag("novelChapterInfo");
        HttpUtils.getInsatance().cancelTag("collectNovel");
        HttpUtils.getInsatance().cancelTag("saveComment");
        HttpUtils.getInsatance().cancelTag("attentionAnChorNovel");
    }
}
